{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 深度学习：基于keras的mnist手写数字识别\n",
    "\n",
    "在深度学习方面，Keras提供了这样一个能够非常方便地搭建神经网络的工具，而且很容易快速上手。mnist手写数字识别是神经网络入门后的一个非常容易上手做的一个程序，尤其是在使用了深度学习框架后，不论是DNN还是CNN，都很简单。这篇文章里，我将介绍一下，使用keras实现mnist手写数字识别的程序。通过这篇文章，你应该就能够学会如何通过keras搭建自己的神经网络了。\n",
    "\n",
    "整个程序的代码思路来源于GitHub 上别人的一个小项目：\n",
    "\n",
    "https://gist.github.com/alexcpn/0683bb940cae510cf84d5976c1652abd\n",
    "\n",
    "首先我们需要导入一些python库\n",
    "\n",
    "## 1.numpy\n",
    "\n",
    "这是python中用于数值计算的库，很多用python做数学建模的应该都不会没有听说过这个库，可以进行矩阵运算以及高维的数组运算，用它来做，比用n个for循环的效率不知道高到哪里去了。\n",
    "\n",
    "然后我们需要设置一下随机数种子"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "np.random.seed(123)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2.keras"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "d:\\ProgramData\\Anaconda3\\lib\\site-packages\\h5py\\__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n",
      "  from ._conv import register_converters as _register_converters\n",
      "Using TensorFlow backend.\n"
     ]
    }
   ],
   "source": [
    "# 从keras模型里面导入序贯模型\n",
    "from keras.models import Sequential\n",
    "# 从keras封装好的层里面导入dense全连接层、Dropout正则化层、Activation激活层和Flatten扁平化层\n",
    "from keras.layers import Dense, Dropout, Activation, Flatten\n",
    "# 从keras封装好的层里面导入二维卷积层和二维最大池化层\n",
    "from keras.layers import Convolution2D, MaxPooling2D\n",
    "from keras.utils import np_utils\n",
    "from tensorflow.examples.tutorials.mnist import input_data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "每一行代码的用途我已经写在了注释里面，其中np_utils在后面会用它将不同类别的标签稀疏正交化\n",
    "\n",
    "## 3.导入数据\n",
    "\n",
    "我们可以看到，原作者是通过keras内置的数据集来训练的，但是因为那个数据集存放在亚马逊云服务器上，在中国大陆我们没办法下载下来，会提示下载失败。本文使用tensorflow载入数据。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Extracting MNIST_data/train-images-idx3-ubyte.gz\n",
      "Extracting MNIST_data/train-labels-idx1-ubyte.gz\n",
      "Extracting MNIST_data/t10k-images-idx3-ubyte.gz\n",
      "Extracting MNIST_data/t10k-labels-idx1-ubyte.gz\n"
     ]
    }
   ],
   "source": [
    "mnist = input_data.read_data_sets(\"MNIST_data/\", one_hot=True)\n",
    "x_train, y_train = mnist.train.next_batch(1000)\n",
    "x_test, y_test = mnist.test.next_batch(50)\n",
    "x_train = x_train.reshape(1000,28,28)\n",
    "x_test = x_test.reshape(50,28,28)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "我们可以查看一下数据的格式，输入输出维度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1000, 28, 28) (1000, 10) (50, 28, 28) (50, 10)\n"
     ]
    }
   ],
   "source": [
    "print(x_train.shape,y_train.shape,x_test.shape,y_test.shape)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4.数据可视化\n",
    "\n",
    "有时候，为了方便，或者更直观，我们往往需要将数据可视化。对于图像数据来说，可视化就是家常便饭了，而且也是最容易可视化的一类数据之一。这里我们需要用到一个强大的绘图库matplotlib，同样，做过数学建模以及仿真的应该都用过这类库，尤其是用过matlab的话。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0. 0. 1. 0. 0. 0. 0. 0. 0. 0.] [0. 0. 1. 0. 0. 0. 0. 0. 0. 0.] [1. 0. 0. 0. 0. 0. 0. 0. 0. 0.] [0. 0. 0. 0. 0. 1. 0. 0. 0. 0.]\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAT4AAAD8CAYAAADub8g7AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAGENJREFUeJzt3X+QVlUZB/DvA8hMij9YfjgbEjRFiJNMEDpMooCGCVOyjToDMzqMUZtJuSg1rjJm5o9oKCqSSlQGTActIVlypqINJWYaB0FSYZElJ3Bzg9CZxGqGiKc/9no457rvfe/7vve9P97z/cww+5z3vPveI/v4cM/Ze88VVQURkU8GZD0AIqK0sfARkXdY+IjIOyx8ROQdFj4i8g4LHxF5h4WPiLxTU+ETkatE5DUROSAi7UkNiihrzO3GJtVewCwiAwHsBzALQA+AHQDmq+re5IZHlD7mduMbVMP3XgzggKq+DgAi8iSAuQBKJoeI8DaR/DiqqiOyHkROVZTbzOtciZXXtUx1RwF4w2r3BK9RMRzMegA5xtwurlh5XcsZn/Tz2vv+5RORVgCtNRyHKG1lc5t5XWy1FL4eAKOt9nkA3gy/SVVXA1gNcEpAhVE2t5nXxVbLVHcHgHEi8mERGQxgHoCOZIZFlCnmdoOr+oxPVU+IyFcB/BbAQABrVHVPYiMjyghzu/FVfTlLVQfjlCBPdqrqlKwH0QiY17kSK6955wYReYeFj4i8w8JHRN5h4SMi77DwEZF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AASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 4 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "# plot 4 images as gray scale\n",
    "plt.subplot(221)\n",
    "print(y_train[155],y_train[1],y_train[2],y_train[3])\n",
    "plt.imshow(x_train[4], cmap=plt.get_cmap('gray'))\n",
    "plt.subplot(222)\n",
    "plt.imshow(x_train[1], cmap=plt.get_cmap('gray'))\n",
    "plt.subplot(223)\n",
    "plt.imshow(x_train[2], cmap=plt.get_cmap('gray'))\n",
    "plt.subplot(224)\n",
    "plt.imshow(x_train[3], cmap=plt.get_cmap('gray'))\n",
    "# show the plot\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
